package resources;

import java.awt.Graphics;
import java.awt.image.*;

public class ImageResource {

	/** The image set this image is from */
	ImageSet sheet;

	/** The row and column of the image on the image sheet  */
	int sheetX, sheetY;

	public int getSheetX() {
		return sheetX;
	}

	public void setSheetX(int sheetX) {
		this.sheetX = sheetX;
	}

	public int getSheetY() {
		return sheetY;
	}

	public void setSheetY(int sheetY) {
		this.sheetY = sheetY;
	}

	BufferedImage image;

	/**
	 * @param parent The tileset this tile is from
	 * @param img This tile image
	 * @param x The column from the tileset
	 * @param y The row from the tileset
	 */
	public ImageResource(ImageSet parent, BufferedImage img, int x, int y) {
		sheet = parent;
		ColorModel cm = img.getColorModel();
		boolean isAlphaPremultiplied = cm.isAlphaPremultiplied();
		WritableRaster raster = img.copyData(null);
		image = new BufferedImage(cm, raster, isAlphaPremultiplied, null);
		sheetX = x;
		sheetY = y;
	}

	public BufferedImage getImage() {
		return image;
	}

	public ImageSet getParent() {
		return sheet;
	}
	
	public Graphics getGraphics() {
		return image.getGraphics();
	}

	public int getHeight(ImageObserver observer) {
		return image.getHeight();
	}

	public int getWidth(ImageObserver observer) {
		return image.getWidth();
	}

	public Object getProperty(String name, ImageObserver observer) {
		return image.getProperty(name, observer);
	}

	public ImageProducer getSource() {
		return image.getSource();
	}

}
